package testcase;

import org.opengauss.jdbc.PgConnection;

import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * 测试建联后修改密码，连接是否会关闭。
 */
public class ChangePasswordTest {
  private static void solve() {
    String url = "jdbc:opengauss://192.168.0.243:14100/testdatabase";
    String username = "testuser";
    String password = "testPassword@1234";
    PgConnection pgConnection;
    try {
      pgConnection = (PgConnection) DriverManager.getConnection(url, username, password);
    } catch (SQLException e) {
      throw new RuntimeException(e);
    }
    while (true) {
      try {
        Statement statement = pgConnection.createStatement();
        boolean resultSet = statement.execute("select 1");
        System.out.println(System.currentTimeMillis() + ": " + resultSet);
        Thread.sleep(1000 * 2);
      } catch (SQLException | InterruptedException e) {
        throw new RuntimeException(e);
      }
    }
  }
  
  public static void main(String[] args) {
    solve();
  }
}
